<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 120px;
            height: 120px;
            background-color: red;
            position: relative;
            top: 2rem;
        }
    </style>
</head>
<body>
    <!-- 计算节点的真实css样式 -->
    <div class="box"></div>
<script src="./js/vue.js"></script>
    <script>
        console.log(getEleCss('.box','top',2))
        /* 获取元素的css值 @param1：元素选择器。@param2：某个css的字符串， @param3:切除最后两位个数 50px => 50   */ 
        function getEleCss(ele,cssMsg,iscut){
            var ele = document.querySelector(ele),eleStyle,num;
            if (window.getComputedStyle) {
                eleStyle = window.getComputedStyle(ele,null);
                num = iscut ? eleStyle[cssMsg].substring(0,eleStyle[cssMsg].length-iscut) : eleStyle[cssMsg];
            } else {
                console.err('your brower is not support')  
                num = ""; 
            }
            return num
        }
    </script>
</body>
</html>